using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.RecipeFramework;
using EnvDTE;
using Microsoft.Practices.RecipeFramework.Library;
using Microsoft.Practices.RecipeFramework.Extensions.CommonHelpers;

namespace Microsoft.Practices.RepositoryFactory.Actions.VisualStudio
{
    /// <summary/>
    public class AddFolderAction : ConfigurableAction
    {
        #region Input Properties

        private Project project;

        /// <summary>
        /// Gets or sets the project.
        /// </summary>
        /// <value>The project.</value>
        [Input(Required=true)]
        public Project Project
        {
            get { return project; }
            set { project = value; }
        }

        private string folderName;

        /// <summary>
        /// Gets or sets the name of the folder.
        /// </summary>
        /// <value>The name of the folder.</value>
        [Input(Required = true)]
        public string FolderName
        {
            get { return folderName; }
            set { folderName = value; }
        }

        #endregion

        #region Output Properties

        private ProjectItem folder;

        /// <summary>
        /// Gets or sets the folder.
        /// </summary>
        /// <value>The folder.</value>
        [Output]
        public ProjectItem Folder
        {
            get { return folder; }
            set { folder = value; }
        }
        #endregion

        #region ConfigurableAction Implementation

        /// <summary>
        /// Executes this instance.
        /// </summary>
        public override void Execute()
        {
            folder = DteHelperEx.FindItemByName(project.ProjectItems, folderName, true);
            
            if(folder == null)
            {
                folder = project.ProjectItems.AddFolder(folderName, "");
            }
        }

        /// <summary>
        /// Undoes this instance.
        /// </summary>
        public override void Undo()
        {
            //Not Implemented
        } 

        #endregion
    }
}
